using Perfect.Marshal;
using System.Xml;

namespace editor
{
namespace cfg.fight
{
[System.Serializable]
public  class AttrArea :   cfg.EditorReadWriter 
 {

    public cfg.fight.AttributeType attrType ;
     public float minValue ;
     public float maxValue ;
     


    public const int TYPE_ID = 249642714;

    public override int GetTypeId() {
        return TYPE_ID;
    }


    public override void MarshalCompatible(Perfect.Marshal.Octets os) {
        os.WriteSize(3);
        os.WriteSize(Tag.INT | (1 << Tag.TAG_SHIFT));  os.WriteInt((int)attrType);  
         os.WriteSize(Tag.FLOAT | (2 << Tag.TAG_SHIFT));  os.WriteFloat(minValue);  
         os.WriteSize(Tag.FLOAT | (3 << Tag.TAG_SHIFT));  os.WriteFloat(maxValue);  
         
    }

    public override void UnmarshalCompatible(Perfect.Marshal.Octets os) {
        for (int _var_num_ = os.ReadSize(); _var_num_-- > 0; ) {
            int _id_ = os.ReadSize();
            switch (_id_)
            {
            case (Tag.INT | (1 << Tag.TAG_SHIFT)):   attrType = (cfg.fight.AttributeType)(os.ReadInt()); break;  
             case (Tag.FLOAT | (2 << Tag.TAG_SHIFT)):   minValue = os.ReadFloat(); break;  
             case (Tag.FLOAT | (3 << Tag.TAG_SHIFT)):   maxValue = os.ReadFloat(); break;  
             
            default: Tag.SkipUnknownField(_id_, os); break;
            }
         }
    }
    public override void MarshalXml(XmlWriter ele)
    {
        ele.WriteAttributeString("type", "AttrArea");
        ele.WriteStartElement("attrType"); ele.WriteAttributeString("id", "1"); ele.WriteEnum(attrType); ele.WriteEndElement();
         ele.WriteStartElement("minValue"); ele.WriteAttributeString("id", "2"); ele.WriteFloat(minValue); ele.WriteEndElement();
         ele.WriteStartElement("maxValue"); ele.WriteAttributeString("id", "3"); ele.WriteFloat(maxValue); ele.WriteEndElement();
         
    }

    public override void UnmarshalXml(XmlElement ele)
    {
        foreach (XmlElement e in ele.GetChildren())
        {
            if (int.TryParse(ele.GetAttribute("id"), out var _id_))
            {
                switch (_id_)
                {
                case 1:  attrType = ele.ReadEnum<cfg.fight.AttributeType>(); break; 
                 case 2:  minValue = ele.ReadFloat(); break; 
                 case 3:  maxValue = ele.ReadFloat(); break; 
                 
                default: break;
                }
            }
            else
            {
                switch (e.Name)
                {
                case "attr_type":  attrType = ele.ReadEnum<cfg.fight.AttributeType>(); break; 
                 case "min_value":  minValue = ele.ReadFloat(); break; 
                 case "max_value":  maxValue = ele.ReadFloat(); break; 
                 
                default: break;
                }
            }
        }
    }
}
}
}
